﻿#include "OperMaterialFE.h"
#include "GUIDialog/GUIPhyscisDialog/MaterialDialogFE.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaMaterial.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"

#include "updateBrowserTable.h"
#include "GUIWidget/AttributeSetDialog.h"

namespace ModelOper
{

    bool ModelOper::OperMaterialFE::execGUI()
    {
        //按钮点击事件触发
        if (_emitter == nullptr) return false;
        const QString name = _emitter->objectName();
        if (name == "actionFEMaterials")
            createMaterial();
        return false;
    }

    bool OperMaterialFE::execProfession()
    {
        return false;
    }

    void OperMaterialFE::createMaterial()
    {
        //弹出对话框
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        GUI::MaterialDialogFE dlg(GUI::PhysicsDlgExecType::Create, -1, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperMaterialFE::duplicateMaterial(const int matID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        GUI::MaterialDialogFE dlg(GUI::PhysicsDlgExecType::Duplicate, matID, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperMaterialFE::editMaterial(const int matID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        GUI::MaterialDialogFE dlg(GUI::PhysicsDlgExecType::Edit, matID, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperMaterialFE::removeMaterial(const int matid)
    {
        //获取材料管理器
        Acoustics::FITKAcousticsDiscModel* disc = Acoustics::FITKAcousticsDiscModel::GetDiscModelFromFrame();
        if (!disc)return ;
        Acoustics::FITKAcousticsFEModel* feModel = disc->getFEModel();
        if (!feModel) return ;
        Interface::FITKMaterialManager * feMgr= feModel->getMaterialManager();
        if (!feMgr)return;
        //移除并更新列表
        feMgr->removeDataByID(matid);
        ModelOper::updateBrowserTable();
    }

    void OperMaterialFE::setAttribute(const QString & name, const QString & currentText, const int attrIndex, const QList<int>& matIDs)
    {
    }
}